package com.itrus.auth.demo.company.bank;

import com.itrus.auth.demo.core.BaseAuth;
import com.itrus.auth.demo.core.Config;
import lombok.extern.slf4j.Slf4j;

import java.util.Map;
import java.util.TreeMap;

/**
 * @author : peigen
 * @since: 2023/8/1 16:59
 */
@Slf4j
public class BankPayAuth extends BaseAuth {

    private String SERVICE_CODE = "idb0041";
    private String REQUEST_PATH = "/enterprise/bankAccount/payment/verificationIdenNewPay";

    public BankPayAuth(Config config) {
        super.config = config;
    }

    @Override
    public String getServiceCode() {
        return SERVICE_CODE;
    }

    /**
     * 申请银行打款
     *
     * @param accountNo      银行账号
     * @param accountBank    总行名称
     * @param keyName        企业名称
     * @param subBank        银行联行号
     * @param payCallbackUrl 打款回调地址
     */
    public void pay(String accountNo, String accountBank, String keyName, String subBank, String payCallbackUrl) {
        Map<String, String> requestMap = new TreeMap();
        requestMap.put("appId", config.getAppId());
        requestMap.put("serviceCode", getServiceCode());
        requestMap.put("accountNo", accountNo);
        requestMap.put("accountBank", accountBank);
        requestMap.put("keyName", keyName);
        requestMap.put("subBank", subBank);
        requestMap.put("payCallbackUrl", payCallbackUrl);

        // 申请银行打款
        doRequest(REQUEST_PATH, requestMap);
    }
}
